﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace ATW.MT.SellManage
{
    public partial class _addPressure : System.Web.UI.Page
    {
        BUS.bus_C_Pressure cp = new BUS.bus_C_Pressure();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Redirect("../Main/Login.aspx");
            }
        }
        protected void queryButton_Click(object sender, EventArgs e)
        {
            string code_c = txtCode_C.Text.Trim();
            string code_s = txtCode_S.Text.Trim();
            string rate = txtRate.Text.Trim();
            decimal _rate = 0;
            try
            {
                if (code_c == "" || code_s == "")
                {
                    Tips("请完整填写公制以及ANSI制的压力等级参数");
                    return;
                }
                if (rate == "")
                {
                    Tips("请填写压力等级价格系数！");
                    return;
                }
                if (!CommonClass.common.filterChar(code_c) || !CommonClass.common.filterChar(code_s))
                {
                    Tips("压力等级参数中存在非法字符！");
                    return;
                }
                if (cp.IsPressExist(code_c, code_s))
                {
                    Tips("该压力等级已经存在！");
                    return;
                }
                if (!decimal.TryParse(rate, out _rate) || _rate <= 0)
                {
                    Tips("价格系数应当为整数或小数！");
                    return;
                }
                int result = cp.PressureAdd(code_c, code_s, rate);
                if (result > 0)
                {
                    Tips("添加成功！");
                    CloseWindowReferesh();
                }
                else
                {
                    Tips("添加失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void Tips(string s)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }//提示
        private void CloseWindowReferesh()
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                if(window.opener)
                {
                    window.opener.location.href=window.opener.location.href;
                    window.close();
                }
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "Close", strScript.ToString());
        }
    }
}